package com.rc.web.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.mybatisflex.core.paginate.Page;
import com.rc.common.annotate.ApiLog;
import com.rc.common.annotate.WithoutTenant;
import com.rc.pojo.dto.farm.FarmPageQuery;
import com.rc.pojo.dto.farm.PoiFarmDTO;
import com.rc.pojo.dto.farm.UpdateFarmDTO;
import com.rc.pojo.po.User;
import com.rc.pojo.vo.farm.FarmDetailVO;
import com.rc.pojo.vo.farm.FarmPageVO;
import com.rc.pojo.vo.farm.FarmVO;
import com.rc.pojo.vo.farm.PoiFarmVO;
import com.rc.web.service.FarmService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 农场表 控制层。
 *
 * @author sym
 * @since 2024-05-26
 */
@RestController
@RequestMapping("/farm")
@Api(tags = "农场")
@RequiredArgsConstructor
@Validated
@Slf4j
public class FarmController {
    private final FarmService farmService;

    @PutMapping
    @ApiOperation("农场管理员更新农场信息")
    public void updateOneById(@RequestBody @Validated UpdateFarmDTO dto) {
        farmService.updateOneById(dto);
    }

    @GetMapping("/{id}")
    @ApiOperation("农场管理员查看农场详情")
    public FarmVO getOneById(@PathVariable Long id) {
        return farmService.getOneById(id);
    }

    @GetMapping("/info")
    @ApiOperation("农场管理员查看农场详情")
    public FarmVO getInfo() {
        User user = StpUtil.getSession().getModel("user", User.class);
        return farmService.getOneById(user.getFarmId());
    }

    @GetMapping("/page")
    @ApiOperation("管理分页查看")
    public Page<FarmPageVO> page(FarmPageQuery dto) {
        return farmService.getPage(dto);
    }

    @GetMapping("/detail/{id}")
    @ApiOperation("顾客查看农场详情")
    @WithoutTenant
    public FarmDetailVO detail(@PathVariable Long id){
        return farmService.detail(id);
    }

    @GetMapping("/poi")
    @ApiOperation("获取经纬度周围的农场")
    @WithoutTenant
    @ApiLog
    public List<PoiFarmVO> getPoi(PoiFarmDTO dto) {
        return farmService.getPoi(dto);
    }
}
